# ############################################################################ #
# #                      File Name: process_options.sh                       # #
# #                          Author: Huaxiao Liang                           # #
# #                         Mail: hxliang666@qq.com                          # #
# #                         04/16/2025-Wed-12:08:45                          # #
# ############################################################################ #

#!/bin/bash
process_options() {
  local message
  for ((i=1; i<=$#; i++)); do
    local arg="${!i}"
    if [[ "$arg" == -* ]]; then
      case "$arg" in
        -short)
          if (( i+1 <= $# )); then
            local val="${!((i+1))}"
            message="This is an short option, its argument is $val."
            echo "$message"
            ((i++))  # 跳过已处理的参数
          fi
          ;;
        --long)
          if (( i+1 <= $# )); then
            local val="${!((i+1))}"
            message="This is an long option, its argument is $val."
            echo "$message"
            ((i++))  # 跳过已处理的参数
          fi
          ;;
      esac
    else
      message="this is an non-option argument."
      echo "$message"
    fi
  done
}

simple_command() {
  echo "In fact, its first parameter is $0."
  echo "The first parameter is $1."
  echo "The second parameter is $2."
}

# 自动执行函数（如果直接运行脚本）
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
    process_options "$@"
fi
